<!DOCTYPE html>
<html>

<head>
  <title>打开小程序</title>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1, maximum-scale=1">
  <meta http-equiv="refresh" content="0;url=weixin://dl/business/?t=Uq1siswot7p">
  <meta name="description" content="点击链接前往微信打开微信小程序~">
  <meta itemprop="name" content="大鹏体验课小程序 - 直达微信小程序">
  <meta itemprop="image" content="https://safe.beer//addons/h5_to_wxapp/icon.jpg">
  <link href="https://safe.beer/addons/h5_to_wxapp/icon.jpg" rel="apple-touch-icon-precomposed">
  <link href="https://safe.beer/addons/h5_to_wxapp/icon.jpg" sizes="114x114" rel="apple-touch-icon-precomposed">

  <script>
        // window.onerror = e => {
        //     console.error(e)
        //     alert('发生错误' + e)
        // }
  </script>
  <!-- weui 样式 -->
  <link rel="stylesheet" href="https://res.wx.qq.com/open/libs/weui/2.4.1/weui.min.css">
  <link rel="stylesheet" href="https://safe.beer//addons/h5_to_wxapp/static/css/home_link.css">
</head>

<body>
  <div id="page" class="page full">
    <div class="safe-notice">
      <img src="https://safe.beer//addons/h5_to_wxapp/static/img/safe.png">
      <p>本链接经过<font style="font-weight: 500;color: #333333;">SSL安全加密</font>,请放心点击!</p>
    </div>

    <!-- 正常打开 -->
    <div class="success hidden" id="success">
      <img class="logo" src="https://safe.beer//addons/h5_to_wxapp/icon.jpg">

      <div id="public-web-container" class="hidden">
        <p class="wxapp_name">正在启动微信小程序</p> <a id="public-web-jump-button" href="javascript:" onclick="openWeapp()"
          class="weui-btn weui-btn_primary weui-btn_loading"><span id="public-web-jump-button-loading"
            class="weui-primary-loading weui-primary-loading_transparent"><i
              class="weui-primary-loading__dot"></i></span>
          进入小程序
        </a>
      </div>
      <!-- wx-open-launch-weapp 父元素剔除 position -->
      <div id="wechat-web-container" class="full flex_cen hidden">
        <div>
          <p class="weui-icon-success weui-icon_msg"></p>
          <p class="mt_10">已成功打开小程序</p>
          <p>若无反应，请尝试点击下方按钮</p>
        </div>
        <!-- path="pages/index/index" -->
        <wx-open-launch-weapp id="launch-btn" username="gh_872ea2b30933" path="pages/index/index?t=1636777002">
          <script type="text/wxtag-template">
            <button style="
                width: 240px;
                height: 45px;
                text-align: center;
                font-size: 17px;
                display: block;
                margin: 0px auto;
                padding: 8px 24px;
                border: none;
                outline: none;
                border-radius: 4px;
                background-color: rgb(7, 193, 96);
                color: rgb(255, 255, 255);">进入小程序</button>
					</script>
        </wx-open-launch-weapp>
      </div>
      <div id="desktop-web-container" class="full desktop-web-container hidden flex_cen">
        <p class="weui-icon-warn weui-icon_msg-primary"></p>
        <p class="mt_10">请扫描下方二维码，使用手机访问</p>
        <div class="qrcodes-container">
          <img class="qrcodes" src="" style="display: inline;">
          </a>
        </div>
      </div>
    </div>
    <!-- 启动失败 -->
    <div class="error hidden" id="error">
      <div class="full flex_cen hidden" id="time-out">
        <div class="center">
          <p class="weui-icon-warn weui-icon_msg-primary"></p>
          <p class="mt_10">链接已过期</p>
        </div>
      </div>
      <div class="full flex_cen hidden" id="params-fail">
        <div class="center">
          <p class="weui-icon-warn weui-icon_msg"></p>
          <p class="mt_10">参数错误</p>
        </div>
      </div>
      <div class="full flex_cen hidden" id="weixin-fail">
        <div class="center">
          <p class="weui-icon-warn weui-icon_msg"></p>
          <p class="mt_10">微信内部暂不支持</p>
          <p class="mt_10">请在外部浏览器打开</p>
        </div>
      </div>
    </div>
  </div>

  <script type="text/javascript" src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.0/jquery.js"></script>
  <!-- 公众号 JSSDK -->
  <script src="https://res.wx.qq.com/open/js/jweixin-1.6.0.js"></script>

  <script>
    var appId = 'wx1c2f67f85c857c8b',
      json = { "pageType": true, "errorType": 0, "openlink": "weixin:\/\/dl\/business\/?t=Uq1siswot7p", "weibolink": "sinaweibo:\/\/wbdiversion?username=gh_872ea2b30933&path=%2Fpages%2Findex%2Findex%3Ft%3D1636777002", "appid": "wx1c2f67f85c857c8b", "name": "\u5927\u9e4f\u4f53\u9a8c\u8bfe\u5c0f\u7a0b\u5e8f", "path": "pages\/index\/index?t=1636777002", "origin_id": "gh_872ea2b30933", "token": "0c0b", "jssdkconfig": { "appId": "wxc964399b21b3361a", "nonceStr": "cYi90ILiVnvOiloe", "timestamp": "1636777002", "signature": "ebee3f0fea64a3de066d7896f76490c3adad6462" }, "shareConfig": { "title": "\u5927\u9e4f\u4f53\u9a8c\u8bfe", "desc": "\u5927\u9e4f\u4f53\u9a8c\u8bfe", "link": "https:\/\/safe.beer\/s.php?s=2e53", "imgUrl": "https:\/\/safe.beer\/\/addons\/h5_to_wxapp\/icon.jpg" } },
      jssdk = json.jssdkconfig,
      openlink = json.openlink,
      weibolink = json.weibolink;

    document.addEventListener("DOMContentLoaded", function () {
      function getQueryVariable(variable) {
        var query = window.location.search.substring(1);
        var vars = query.split("&");
        for (var i = 0; i < vars.length; i++) {
          var pair = vars[i].split("=");
          if (pair[0] == variable) {
            return pair[1];
          }
        }
        return (false);
      }
      function docReady(fn) {
        if (document.readyState === 'complete' || document.readyState === 'interactive') {
          fn()
        } else {
          document.addEventListener('DOMContentLoaded', fn);
        }
      }
      //判断是否是微信浏览器的函数
      function isWeiXin() {
        var ua = navigator.userAgent.toLowerCase()
        var isWXWork = ua.match(/wxwork/i) == 'wxwork'
        var isWeixin = !isWXWork && ua.match(/micromessenger/i) == 'micromessenger'
        return isWeixin;
      }
      //判断是否是百度浏览器浏览器的函数,百度不能调起其他APP
      function isBaidu() {
        ua = navigator.userAgent.toLowerCase();
        if (ua.indexOf('baiduboxapp/') > -1) {
          return true;
        } else {
          return false;
        }
      }
      function isUc() {
        if (navigator.userAgent.match(/(UCBrowser|Quark)/i)) {
          return true;
        } else {
          return false;
        }
      }
      function isWeibo() {
        var ua = navigator.userAgent;
        if (ua.indexOf('Weibo') > -1) {
          return true;
        } else {
          return false;
        }
      }
      function isMobile() {
        if (navigator.userAgent.match(/(phone|pad|pod|iPhone|iPod|ios|iPad|Android|Mobile|XiaoMi|IEMobile)/i)) {
          return true;
        } else {
          return false;
        }
      }

      docReady(async function () {
        var ua = navigator.userAgent.toLowerCase()
        var isWXWork = ua.match(/wxwork/i) == 'wxwork'
        var isWeixin = !isWXWork && ua.match(/micromessenger/i) == 'micromessenger'
        var isMobile = false
        var isDesktop = false
        var baidu = isBaidu()
        var uc = isUc()
        var weibo = isWeibo()

        if (navigator.userAgent.match(
          /(phone|pad|pod|iPhone|iPod|ios|iPad|Android|Mobile|IEMobile)/i)) {
          isMobile = true
        } else {
          isDesktop = true
        }

        if (isWeixin) { // 微信内
          var containerEl = document.getElementById('wechat-web-container')
          containerEl.classList.remove('hidden')
          containerEl.classList.add('full', 'wechat-web-container')

          var launchBtn = document.getElementById('launch-btn')
          launchBtn.addEventListener('ready', function (e) {
            console.log('开放标签 ready')
          })
          launchBtn.addEventListener('launch', function (e) {
            console.log('开放标签 success')
          })
          launchBtn.addEventListener('error', function (e) {
            console.log('开放标签 fail', e.detail)
          })

          if (jssdk) {
            wx.config({
              // debug: true, // 调试时可开启
              appId: jssdk.appId, // <!-- replace -->
              timestamp: jssdk.timestamp, // 必填，填任意数字即可
              nonceStr: jssdk.nonceStr, // 必填，填任意非空字符串即可
              signature: jssdk.signature, // 必填，填任意非空字符串即可
              jsApiList: ['updateTimelineShareData', 'updateAppMessageShareData'], // 必填，随意一个接口即可 
              openTagList: ['wx-open-launch-weapp'], // 填入打开小程序的开放标签名
            })
            wx.ready(function () {
              var shareConfig = json.shareConfig;
              wx.updateTimelineShareData(shareConfig)
              wx.updateAppMessageShareData(shareConfig)
            });

            if (json.pageType) {
              // post 触达
              var url = location.href;
              $.ajax({
                type: 'POST',
                url: url,
                data: { act: 'enter', token: json.token },
                success: function (res) {
                  console.log(res);
                },
              });

              if (json.openlink && json.flag == 0) {
                location.href = json.openlink
              }
              // wx.closeWindow();
            }
          }
        } else if (isDesktop) {
          // 在 pc 上则给提示引导到手机端打开
          var containerEl = document.getElementById('desktop-web-container')
          containerEl.classList.remove('hidden')
          containerEl.classList.add('full', 'desktop-web-container')

          var containerEl2 = document.getElementById('public-web-container')
          containerEl2.classList.add('hidden')
        } else {
          var containerEl2 = document.getElementById('public-web-container')
          containerEl2.classList.remove('hidden')

          var buttonEl = document.getElementById('public-web-jump-button')
          var buttonLoadingEl = document.getElementById('public-web-jump-button-loading')

          if (weibo) {
            openlink = weibolink;
          }
          try {
            await openWeapp(() => {
              buttonEl.classList.remove('weui-btn_loading')
              buttonLoadingEl.classList.add('hidden')
            })
          } catch (e) {
            buttonEl.classList.remove('weui-btn_loading')
            buttonLoadingEl.classList.add('hidden')
            throw e
          }
        }

        // 状态显示
        let pageType = json.pageType
        let errorType = json.errorType
        var success = document.getElementById('success')
        var error = document.getElementById('error')
        let weixinFail = document.getElementById("weixin-fail")

        if (pageType) {
          success.classList.remove('hidden')
          if (isWeixin) {
            if (!jssdk) {
              error.classList.remove('hidden')
              weixinFail.classList.remove('hidden')

              var containerEl = document.getElementById('wechat-web-container')
              containerEl.classList.add('hidden')
            }
          }
        } else {
          error.classList.remove('hidden')
          let timeOut = document.getElementById("time-out")
          let paramsFail = document.getElementById("params-fail")
          if (errorType === 1) {
            timeOut.classList.remove('hidden')
          } else {
            paramsFail.classList.remove('hidden')
          }
        }
      })
      async function openWeapp(onBeforeJump) {
        if (json.pageType) {
          // post 触达
          var url = location.href;
          $.ajax({
            type: 'POST',
            url: url,
            data: { act: 'enter', token: json.token },
            success: function (res) {
              console.log(res);
            },
          });
          if (openlink && json.flag == 0) {
            location.href = openlink
          }
        }
      }
    });
  </script>
  <script>;</script>
  <script type="text/javascript" src="https://safe.beer/app/index.php?i=9&c=utility&a=visit&do=showjs&m="></script>
</body>

</html>